package com.guc.md

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import com.guc.kframe.utils.LogG
import com.guc.kframe.utils.ToastUtil
import com.guc.kframe.utils.afterTextChanged
import com.guc.kframe.utils.quickStartActivity
import com.guc.gviewbinding.inflate
import com.guc.md.databinding.ActivityForthBinding

class ForthActivity : AppCompatActivity() {
    private val TAG = ForthActivity::class.java.name
    private val binding: ActivityForthBinding by inflate()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setSupportActionBar(binding.toolbar)
        supportActionBar?.run {
            setDisplayHomeAsUpEnabled(true)
            setHomeAsUpIndicator(R.drawable.icon_back)
        }
        init()
    }

    private fun init() {
        binding.etText.afterTextChanged {
            binding.textInputLayout.error = null
        }
        binding.btnSubmit.setOnClickListener {
            binding.textInputLayout.error = "账号错误"
        }
        binding.bnv.apply {
            setOnNavigationItemReselectedListener {
                LogG.loge(TAG, it.toString())
            }
            setOnNavigationItemSelectedListener {
                LogG.loge(TAG, it.toString())
                when (it.itemId) {
                    R.id.item_1 ->
                        ToastUtil.toast("设置")
                    R.id.item_2 -> ToastUtil.toast("评论")
                    R.id.item_3 -> ToastUtil.toast("提示")
                }
                true
            }
        }
        binding.fabNext.setOnClickListener {
            quickStartActivity<BottomSheetActivity>(this) {}
        }
        binding.btnBehavior.setOnClickListener {
            quickStartActivity<BehaviorActivity>(this) {}
        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        this.finish()
        return super.onOptionsItemSelected(item)
    }

}